﻿namespace EyeOpen.SilverlightConverter
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml.Linq;

    internal static class XElementExtension
    {
        public static IEnumerable<XElement> GetNodesFromName(this XElement element, string nodeName)
        {
            return
                from descendant in element.Descendants()
                where descendant.Name.LocalName == nodeName
                select descendant;
        }

        public static void AddNodeWithValue(this XElement element, XNamespace xnsp, string nodeName, string value)
        {
            element.Add(new XElement(xnsp + nodeName, value));
        }

        public static void AddNodeWithAttribute(this XElement element, XNamespace xnsp, string nodeName, string attributeName, string attributeValue)
        {
            XElement node = new XElement(xnsp + nodeName);
            node.SetAttributeValue(attributeName, attributeValue);
            element.Add(node);
        }
    }
}
